// function ban(){
//     var shu ;
//     var node = $('#tt').tree('getSelected');
//     if (node){
//         var s = node.text;
//         if (node.attributes){
//             s += ","+node.attributes.p1+","+node.attributes.p2;
//         }
//         shu = s;
//     }
//     console.log("树："+shu);
//     // var shi = $("#test6").val();
//     // console.log("时间："+shi);
//     var type = $("#type").val();
//     console.log("状态"+type)
//
//     var men = $("#men").val();
//     console.log("选择"+men);
//
//     $.post("../house/list",{"shu":shu,"type":type,"number":men,"pageNumber":0,"pageSize":2},function(){
//
//     })
//
// }


$(function () {

    $('#men').selected({
        maxHeight: '400px'
    });


    $('#table').bootstrapTable({
        url: '${pageContext.request.contextPath}/../../house/list',
        columns: [
            {
                field: 'id',
                title: 'id',
                visible : false,
            },{
                field: 'doornumber',
                title: '房屋门牌号'
            }, {
                field: 'typeb.id',
                title: '房屋状态',
                formatter: function (value, row, index) {
                    if (row.typeb.id == 1) {
                        return "空闲";
                    } else {
                        return "已售";
                    }
                }

            },{
                field: 'userdetails.name',
                title: '姓名',
                // visible : false,
            },
            {
                field: 'userdetails.phone',
                title: '手机号',
                // visible : false,
            },
            {
                field: 'userdetails.rundate',
                title: '入住时间',
                formatter: function (value, row, index) {

                    if(row.userdetails!=null){
                        //console.log(row.userdetails[0].name);
                        if(row.userdetails.name!=null){
                            if(row.userdetails.rundate==null) {
                                return "双击入住";
                            }
                        }else{
                            return row.userdetails.rundate;
                        }
                    }
                },

            },{
                field: 'userdetails.sfz',
                title: '身份证号码',
                // visible : false,
            },{
                field: 'userdetails.property.name',
                title: '产权',
                // visible : false,
            },
             {
                field: 'sale.name',
                title: '楼'
            }, {
                field: 'danyuan.name',
                title: '单元'
            }, {
                field: 'floor',
                title: '层数'
            }, {
                field: 'huxing.name',
                title: '户型'
            }, {
                field: 'direction.name',
                title: '房屋朝向'
            }, {
                field: 'measure',
                title: '平米',
                formatter: function (value, row, index) {
                    var jia = row .measure+"平方米";
                    return jia;
                }
            },{
                field:'remark',
                title:'简介'
            }
        ],onClickRow: function (row, $element, field) {
            if(row.userdetails!=null){
                $("#name").text(row.userdetails.name);
                $("#menpaihao").text(row.doornumber);
                $("#yin2").val(row.id);
                $.post("${pageContext.request.contextPath}/../../srecord/cc2",{"orderid":row.id,"type":1},function(date){
                    $("#table2").bootstrapTable("load",date);
                })
            }else{
                $("#name").text("");
                $("#menpaihao").text("");
                $.post("${pageContext.request.contextPath}/../../srecord/cc2",{"orderid":row.id,"type":1},function(date){
                    $("#table2").bootstrapTable("load",date);
                })
            }

        },
        contentType:"application/x-www-form-urlencoded",
        queryParamsType: '',
        //修改分页的默认对数
        //offset,limit
        height: 300,
        pageNumber: 1,
        pageSize: 5,
        pagination:true,
        queryParams: queryParams,
        sidePagination:'server',
    });
    $("#table2").bootstrapTable({
        url:'',
        columns: [{
            checkbox : true
        },{
            field: 'id',
            title: 'id',
            visible : false,
        },{
            field: 'lasttime',
            title: '上次读数'
        },{
            field: 'sdate',
            title: '上次日期'
        },{
            field: 'jdate',
            title: '缴费期限'
        },{
            field: 'costitem.name',
            title: '收费名称'
        },{
            field:'num',
            title:'用量',
        },{
            field:'zmoney',
            title:'金额',
        },{
            field:'type',
            title:'是否缴费',
            formatter: function (value, row, index) {
                if(row.type==1){
                    return "未交费";
                }else if(row.type==2){
                    return "已缴费";
                }
            }
        }
        ],
        height:350
    })

})

function queryParams(params) {
    var shu ;
    var node = $('#tt').tree('getSelected');
    if (node){
        var s = node.text;
        if (node.attributes){
            s += ","+node.attributes.p1+","+node.attributes.p2;
        }
        shu = s;
    }
    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        'pageSize': params.pageSize,  //页面大小
        'pageNumber': params.pageNumber, //页码
        'shu':shu,
        'type' :$ ('#typexuan').val(),
        'number':$("#men").val(),
    };
    return temp;
};


function search() {
    var opt = $("#table").bootstrapTable('getOptions');

    var shu ;
    var node = $('#tt').tree('getSelected');
    if (node){
        var s = node.text;
        if (node.attributes){
            s += ","+node.attributes.p1+","+node.attributes.p2;
        }
        shu = s;
    }

    var type = $("#typexuan").val();
    var men = $("#men").val();

    $.post('${pageContext.request.contextPath}/../../house/list', {
        'shu':shu,
        'type': type,
        'number':men,
        'pageSize': opt.pageSize,
        'pageNumber': 1
    }, function (data) {

        //重新给table绑定数据
        $("#table").bootstrapTable("load", data);
    });

}



function jiao() {
    var arr = $("#table2").bootstrapTable('getAllSelections');
    if (arr.length == 0) {
        sweetAlert("你没有选中任何缴费项");
    } else {
        $('#your-modal').modal(open);

        var money = 0;
        $.each(arr, function(i, e) {
            money = money+e.zmoney;
        });
        $("#money").val(money);
    }
}

function jiao2() {
    var arr = $("#table2").bootstrapTable('getAllSelections');
    if (arr.length == 0) {
        sweetAlert("你没有选中任何缴费项");
    } else {

        if($("#zl").val()<0){
            sweetAlert("已交金额不足！")
        }else{
            var yin2 = $("#yin2").val();
            var date = $("#date").val();
            var zhong = $("#money").val();
            var remark = $("#remark").val();
            $.post("${pageContext.request.contextPath}/../../jiaofeidan/add",{"house.id":yin2,"date":date,"money":zhong,"remark":remark},function(date){
                var a = date;
                $.each(arr, function(i, e) {
                    $.post("${pageContext.request.contextPath}/../../jfxq/add",{"lasttime":e.lasttime,"sdate":e.sdate,"jiaofeidan.id":a.id,"costitem.id":e.costitem.id,"number":e.num,"zmoney":e.zmoney},function(data){
                        $.post("${pageContext.request.contextPath}/../../srecord/upd",{"id":e.id},function(data){
                            sweetAlert("缴费成功！")
                        })
                    })
                });
                $('#your-modal').modal(close);
            })

        }
    }
}

function qian(){
    var money = $("#money").val();
    var xian = $("#jine").val();
    $("#zl").val(xian-money);
}

